﻿using System;
using System.Collections.Generic;
using System.Text;
using T.FAS.Runtime.Metadata.Entity;
using T.FAS.Runtime.Base.Entity;

namespace T.FAS.Runtime.Action.SPI
{
    public class ActionExecContext
    {
        /// <summary>
        /// 元数据ID
        /// </summary>
        public string MetadataID { get; set; }
        /// <summary>
        /// 元数据Code
        /// </summary>
        public string MetadataCode { get; set; }
        /// <summary>
        /// 动作类型
        /// </summary>
        public ActionType ActionType { get; set; }
        /// <summary>
        /// 动作名称
        /// </summary>
        public string ActionCode { get; set; }
        /// <summary>
        /// Cookies
        /// </summary>
        public Dictionary<string,string> Cookies { get; set; }
        /// <summary>
        /// 动作插件信息
        /// </summary>
        public ActionPluginInfo ActionPlugin { get; set; }
        /// <summary>
        /// 数据信息
        /// </summary>
        public Dictionary<string,object> DataContent { get; set; }
        /// <summary>
        /// 远程调用入参
        /// </summary>
        public List<ActionParameter> RemoteInvokeParameter { get; set; }
       
        /// <summary>
        /// 元数据
        /// </summary>
        public IMetaDataContent MetaData { get; set; }
        /// <summary>
        /// 依赖的元数据
        /// </summary>
        public List<FASMetaData> DependencyMetaDatas { get; set; }
        /// <summary>
        /// 应用ID
        /// </summary>
        public string AppID { get; set; }

        /// <summary>
        /// 原始的Action元数据，用于CDO的CRUD方法转换时，保存原始的Action定义信息
        /// </summary>
        public IMetaDataContent OriginalActionMetaData { get; set; }
        /// <summary>
        /// 统一的上下文信息
        /// </summary>
        public FASContext FASContext { get; set; }
        /// <summary>
        /// 用于构造RemoteInvoke调用时的上下文数据
        /// </summary>
        public RemoteInvokeContext RemoteInvokeContext { get; set; }
        public void AddParamOverride(string key,object value)
        {
            if (DataContent == null)
                DataContent = new Dictionary<string, object>();
            DataContent[key] = value;
        }
        /// <summary>
        /// 是否是批量更新操作
        /// </summary>
        public bool IsBatchUpdateAction { get; set; }

        public ActionExecContext Copy()
        {
            return new ActionExecContext()
            {
                MetadataID = this.MetadataID,
                MetadataCode = this.MetadataCode,
                ActionType = this.ActionType,
                ActionCode = this.ActionCode,
                ActionPlugin = this.ActionPlugin == null ? null:this.ActionPlugin.Copy(),
                DataContent = this.DataContent,
                DependencyMetaDatas = this.DependencyMetaDatas,
                RemoteInvokeParameter = this.RemoteInvokeParameter,
                MetaData = this.MetaData,
                AppID = this.AppID,
                OriginalActionMetaData = this.OriginalActionMetaData,
                FASContext = this.FASContext
            };
        }
    }
}
